# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'CommandLauncher.ui'
#
# Created: Thu Mar 11 21:16:22 2010
#      by: PyQt4 UI code generator 4.6
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui
import CommandSelector


class Ui_CommandLauncherUI(object):
    def setupUi(self, CommandLauncherUI):
        CommandLauncherUI.setObjectName("CommandLauncherUI")
        CommandLauncherUI.resize(400, 404)
        self.CommandBox = QtGui.QPlainTextEdit(CommandLauncherUI)
        self.CommandBox.setGeometry(QtCore.QRect(20, 10, 361, 31))
        self.CommandBox.setObjectName("CommandBox")
        self.CommandList = QtGui.QListWidget(CommandLauncherUI)
        self.CommandList.setGeometry(QtCore.QRect(20, 80, 361, 301))
        self.CommandList.setObjectName("CommandList")
        self.RunButton = QtGui.QPushButton(CommandLauncherUI)
        self.RunButton.setGeometry(QtCore.QRect(340, 50, 51, 27))
        self.RunButton.setObjectName("RunButton")
        self.label = QtGui.QLabel(CommandLauncherUI)
        self.label.setGeometry(QtCore.QRect(30, 50, 291, 20))
        self.label.setObjectName("label")
        self.commandselector=CommandSelector.CommandSelector()
        self.currentcommand=""
        for item in self.commandselector.GetSuggestionList(''):
            self.CommandList.addItem(item)
        self.retranslateUi(CommandLauncherUI)
        QtCore.QObject.connect(self.CommandBox, QtCore.SIGNAL("textChanged()"), self.handleTextChanged)
        QtCore.QObject.connect(self.RunButton, QtCore.SIGNAL("clicked()"), self.Execute)
        QtCore.QObject.connect(CommandLauncherUI, QtCore.SIGNAL("destroyed()"), self.LeaveActions)
        QtCore.QObject.connect(self.CommandList, QtCore.SIGNAL("itemClicked(QListWidgetItem*)"), self.ListClicked)
        QtCore.QMetaObject.connectSlotsByName(CommandLauncherUI)


    def retranslateUi(self, CommandLauncherUI):
        CommandLauncherUI.setWindowTitle(QtGui.QApplication.translate("CommandLauncherUI", "GlassBeadLauncher", None, QtGui.QApplication.UnicodeUTF8))
        self.RunButton.setText(QtGui.QApplication.translate("CommandLauncherUI", "Run", None, QtGui.QApplication.UnicodeUTF8))
        self.label.setText(QtGui.QApplication.translate("CommandLauncherUI", "Run :", None, QtGui.QApplication.UnicodeUTF8))

    def ListClicked(self):
        self.currentcommand=self.CommandList.selectedItems()[0].text()
        self.Execute()
        

    def LeaveActions(self):
        self.commandselector.Save()
        

    def Execute(self):
        self.commandselector.ExecuteCommand(str(self.currentcommand))
        self.commandselector.Save()
        

    def handleTextChanged(self):
        searchkey=self.CommandBox.document().toPlainText()
        self.currentcommand=self.commandselector.GetAutoCompletedCommand(searchkey)
        if self.currentcommand=="":
            self.currentcommand=searchkey
        self.label.setText("Run "+self.currentcommand)
        self.CommandList.clear()
        for item in self.commandselector.GetSuggestionList(searchkey):
            self.CommandList.addItem(item)

        #self.CommandList.addItems(self.commandselector.GetSuggestionList(searchkey))

if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    CommandLauncherUI = QtGui.QWidget()
    ui = Ui_CommandLauncherUI()
    
    ui.setupUi(CommandLauncherUI)
    CommandLauncherUI.show()
    sys.exit(app.exec_())
    
